﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Service.ZSJL.Com.IO
{
    public class XmlUtil
    {
        public static string XmlSerialize<t>(t obj)
        {
            string xmlstring = string.Empty;
            XmlSerializer xmlserializer = new XmlSerializer(typeof(t));
            using (MemoryStream ms = new MemoryStream())
            {
                xmlserializer.Serialize(ms, obj);
                xmlstring = Encoding.UTF8.GetString(ms.ToArray());
            }
            return xmlstring;
        }

        public static string BuilXml(SortedList<string, string> so)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<xml>");
            int reint = 0;
            if (so != null)
                foreach (var dd in so)
                {
                    if (!string.IsNullOrEmpty(dd.Value))
                    {
                      
                            sb.Append(string.Format("<{0}><![CDATA[{1}]]></{0}>", dd.Key, dd.Value));
                     
                    }

                }
            sb.Append("</xml>");

            return sb.ToString();
        }
    }
}
